package com.ihr360.payroll.controller.monitor;

import com.ihr360.job.endpoint.PoolStatus;
import com.ihr360.job.endpoint.ThreadPoolStatus;
import com.ihr360.maven.plugin.ModuleCodeStore;
import com.ihr360.maven.plugin.annotation.FunctionDefinition;
import com.ihr360.maven.plugin.annotation.ModuleDefinition;
import com.ihr360.payroll.model.dto.batch.BatchExecuatorStatus;
import com.ihr360.payroll.service.batch.BatchExecuatorStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/monitor"})
@ModuleDefinition(mainModuleCode = ModuleCodeStore.Module.SALARY_CODE_ADMIN,
        mainModuleName = ModuleCodeStore.Module.SALARY_NAME_ADMIN,
        subModuleCode = ModuleCodeStore.Module.SalaryAdmin.BATCH_JOB_EXECUTION_CODE,
        subModuleName = ModuleCodeStore.Module.SalaryAdmin.BATCH_JOB_EXECUTION_NAME)
public class SalaryTaskExecutorController {
    @Autowired
    private BatchExecuatorStatusService batchExecuatorStatusService;

    @Autowired
    private ThreadPoolStatus threadPoolStatus;

    @RequestMapping("/executors/status/check")
    @FunctionDefinition(functionName = "任务执行者状态校验", functionCode = ModuleCodeStore.Function.VIEW)
    public PoolStatus check() {
        return threadPoolStatus.getPoolStatus();
    }

    @RequestMapping("/executors/status")
    @FunctionDefinition(functionName = "获取所有任务状态", functionCode = ModuleCodeStore.Function.VIEW)
    public Iterable<BatchExecuatorStatus> status() {
        return batchExecuatorStatusService.poolStatus();
    }


}